package com.utils;

import com.config.ContextUtils;

import java.io.File;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/5/1 13:12
 * @since JDK 1.8
 */
public class CommonUtils {

    public static Method getMethod(String method, Class<?> cls){
        Method[] methods=cls.getDeclaredMethods();
        int size=methods.length;
        for (int i = 0; i < size; i++) {
            Method method1=methods[i];
            if(!method1.getName().equals(method)){
                continue;
            }
            return method1;
        }
        return null; //
    }

    /**
     * 获取公共文件的配置信息
     * @return
     */
    public static String getProValueByKey(String key){
        Map<String, String> stringStringMap= ContextUtils.getBeanObj("commonpro");
        return stringStringMap.get(key);
    }

    public static String getFilePathBykey(String key){
        String path=getProValueByKey(key);
        String sysTemPath=getSystemPath();
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(sysTemPath)
                .append(File.separator);
        String[] paths=path.split("-");
        for (int i = 0; i < paths.length; i++) {
            stringBuilder.append(File.separator)
                    .append(paths[i]);
        }
        return stringBuilder.toString();
    }



    public static void main(String[] args) {
        String str="SpringBootNoteManager-src-main-resources-templatespath111";
        str=str.replaceAll("-",File.separator);
        System.out.println(str);
        System.out.println( getSystemPath());
    }
    public static String getSystemPath(){
        return System.getProperty("user.dir");
    }

}
